<template>
	<view class="container">
		<view class="top">			
			<view class="search"><view class="small"><image src="/static/search.png" /></view><view class="input"><input type="text" placeholder="搜索" @input="InputNickName" confirm-type="search" @confirm="Search"/></view></view>
			<view class="order" @click="Sort()">离我最近</view>
			<view class="sort" :style="Order=='asc'?'':'transform: rotate(180deg);'"><image src="/static/sanjiao.png" /></view>
		</view>
		<view class="list" v-for="Info in List" @click="RoomInfo(Info.ID)">
			<view class="img"><image :src="Tools.GetImg(Info.Img,500)" mode="aspectFill" /></view>
			<view class="right">
				<view class="name"><view class="realname">{{Info.Name}}</view><view class="distance">{{Info.Distance}}</view></view>
				<view class="brief">{{Info.Brief}}</view>
				<view class="pos"><view class="small"><image src="/static/position3.png"/></view><view class="address">{{Info.Address}}</view></view>
			</view> 
		</view>
		<view class="nodata" v-if="NoData"></view>
		<view class="loadmore">{{Tip}}</view>
	</view>
</template>

<script>
	export default {
		onShareAppMessage: function() {
			var UserID = uni.getStorageSync("UserID");
		    return {
		      title: "相亲角",
		      path: "pages/room/roomlist?ParentID="+UserID+"&ID="+this.ID//这是一个路径
		    }
		},
		data() {
			return {
				Lat:0, 
				Lng:0,
				Order:"",
				Tip:'正在加载...',
				Page:1,
				List:[],
				NoData:false,
				LoadMore:true,
				Keyword:'',
			};
		}, 
		onPullDownRefresh() {
			this.Re_Load();
		},
		onReachBottom() {
			if(this.LoadMore){
				this.Page++;
				this.Find_Pager();
			}
		},
		onShow() {
			this.Util.MatcherIsIdentify();
		},
		onLoad(options) {
			this.Util.SetParam(options); 
			uni.getLocation({
			  type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
			  success: res=> {
			      this.Lat = res.latitude; // 纬度，浮点数，范围为90 ~ -90
			      this.Lng = res.longitude; // 经度，浮点数，范围为180 ~ -180。	
				  this.Find_Pager();
			  },
			  fail: res=>{
				  this.Find_Pager();
			  }
			});		
		},			
		methods:{
			Sort(){
				this.Util.AddPushCount();
				this.Order=this.Order=="asc"?"desc":"asc";
				this.Re_Load();
			},
			InputNickName(e){
				this.Keyword = e.detail.value;
			},
			Search(){
				this.Re_Load();
			},
			RoomInfo(ID){
				this.Util.AddPushCount();
				uni.navigateTo({
					url:"/pages/room/roominfo?ID="+ID 
				})
			},
			Find_Pager(){
				var data = {};
				data.Act="Find_Room";
				data.Page=this.Page;
				data.Keyword=this.Keyword;
				data.Limit=20;
				data.Lat = this.Lat;
				data.Lng = this.Lng;
				data.Order=this.Order;
				this.Util.Loading("加载中...");
				this.Util.Post(data, json=>{
					this.Util.HideLoading();
					uni.stopPullDownRefresh();
					this.List= this.List.concat(json.Data.List);
					if(json.Data.Count==0){
						this.NoData=true;
						this.Tip="没有找到任何相亲角";
					}
					else if(this.List.length>=json.Data.Count){
						this.LoadMore=false;
						this.Tip="我是有底线的";
					}
				});
			},
			Re_Load(){
				this.List=[];
				this.Page=1; 
				this.NoData=false;
				this.LoadMore=true;
				this.Tip='正在加载...';
				this.Find_Pager();
			}
		}
	}
</script>

<style lang="scss">
	.container{width:100%; padding:20rpx;
		.top{width:100%; height:85rpx; display: flex; flex-direction: row;
			.search{flex:1; height:70rpx; padding-top:14rpx; padding-left:20rpx; float:left; border-radius: 35rpx; background-color:#ffffff; display: flex; flex-direction: row;
				.small{width:40rpx; height:40rpx; margin-top:6rpx; image{width:100%; height:100%;}}
				.input{flex:1; height:50rpx; line-height: 50rpx; padding-left:10rpx;}
			}
			.order{width:auto; height:70rpx; line-height: 70rpx; margin-left:15rpx; margin-right: 10rpx; border-radius: 10rpx; text-align: left;}
			.sort{width:24rpx; height:70rpx; line-height:70rpx; image{width:100%; height:24rpx;}} 
		}
		.list{width:100%; height:auto; padding:15rpx; border-radius: 20rpx; margin-bottom: 20rpx; background-color: #ffffff; display: flex; flex-direction: row;
			.img{width:300rpx; height: 200rpx; float:left; image{width:100%; height:100%; border-radius: 20rpx;}}
			.right{flex:1; padding-left:10rpx; padding-right: 10rpx;
				.name{width:100%;  padding-left:5rpx; float:left; display: flex; flex-direction: row;
					.realname{flex:1; max-height: 84rpx; font-size:36rpx; line-height: 42rpx; overflow: hidden; font-weight: bold; float:left;}
					.distance{width:auto; font-size:28rpx;  float:right; color:#757575;}
				}
				.brief{width:100%; height:80rpx; line-height: 36rpx; padding-left:5rpx; padding-top:8rpx; margin-bottom: 8rpx; font-size:30rpx; overflow: hidden;}
				.pos{width:100%; display: flex; flex-direction: row; font-size:28rpx;
					.small{width:40rpx; height:40rpx; image{width:100%; height:100%;}}
					.address{flex:1; height:68rpx; line-height: 34rpx; margin-top:3rpx; overflow: hidden; color:#757575;}
				}
			}
		}
		.list:active{background-color:#f6f6f6 ;}
	}
</style>
